package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.message.ArticleVisitStreamMess;
import com.heima.common.constants.message.HotArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Version: V1.0
 */
@Component
@Slf4j
public class ArticleIncrHandleListener {

    @Autowired
    ApArticleService apArticleService;

    @KafkaListener(topics = HotArticleConstants.HOTARTICLE_INCR_HANDLE_OUPUT_TOPIC)
    public void receiveMessage(String message){
         log.info("ArticleIncrHandleListener receiveMessage:{}", message);
         // 更新数据库的4个0，更新热点文章缓存redis
        apArticleService.updateApArticle(JSON.parseObject(message, ArticleVisitStreamMess.class));
    }

}
